﻿using System.Collections;
using System.Web;
using System.Web.Caching;

namespace BBCode.Template
{
    public class CacheProvider : ICacheProvider
    {
        /// <summary>
        /// Gets the cache.
        /// </summary>
        private Cache cache
        {
            get { return HttpRuntime.Cache; }
        }

        #region ICacheProvider Members

        /// <summary>
        /// Inserts the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        public void Insert(string key, object item)
        {
            cache.Insert(key, item);
        }

        /// <summary>
        /// Gets the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public object Get(string key)
        {
            return cache.Get(key);
        }

        /// <summary>
        /// Removes the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        public void Remove(string key)
        {
            cache.Remove(key);
        }

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
        public IEnumerator GetEnumerator()
        {
            return cache.GetEnumerator();
        }

        #endregion
    }
}